//
//  YJMWeiBoModel.swift
//  Weibo
//
//  Created by 杨军民 on 16/7/24.
//  Copyright © 2016年 杨军民. All rights reserved.
//

import UIKit

//微博模型
class YJMWeiBoModel: NSObject {
    
    ///微博ID
    var ID : Int64 = 0
    
    ///微博创建时间
    var created_at : String?
    
    ///微博信息内容
    var text : String?
    
    ///微博来源
    var source : String?
    
    ///微博配图
    var pic_urls : [[String: AnyObject]]?
    
    ///转发数
    var reposts_count : Int = 0
    
    ///评论数
    var comments_count: Int = 0
    
    ///表态数
    var attitudes_count: Int = 0
    
    ///用户模型
    var user : YJMUserModel? {
        didSet{
            //字典
            //字典转模型
            //自己重新复制
            //在didSet给自己赋值将不会在调用didSet
        }
    }
    
    init(dic: [String: AnyObject]) {
        super.init()
        
        //kvc
        setValuesForKeysWithDictionary(dic)
    }
    
    //自己字典转模型
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            //讲value转换成字典
            if let dic = value as? [String: AnyObject]{
                //字典转模型
                user = YJMUserModel(dic:dic)
            }
            return
        }
        //要是其他的key就正常的走
        super.setValue(value, forKey: key)
    }
    
    //当获取到的数据没有全部使用就会导致系统崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        print("什么都不需要做")
    }
    
    //打印
    override var description: String{
        get{
//            print("ID:\(ID),created_at\(created_at),text\(text),source\(source),pic_urls\(pic_urls),reposts_count\(reposts_count),comments_count\(comments_count),attitudes_count\(attitudes_count)")
            //根据key值打印
            let keys = ["ID","created_at","text","source","pic_urls","reposts_count","comments_count","attitudes_count"]
    
            return "\n\n微博类型:" + dictionaryWithValuesForKeys(keys).description
        }
    }
}
